package com.bishe.serivce.Impl;

import cn.hutool.core.util.StrUtil;
import com.bishe.dao.CheckworkDao;
import com.bishe.pojo.Checkwork;
import com.bishe.serivce.ICheckworkService;
import com.bishe.utils.JobUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * 考情接口实现
 * @date 2022/03/20 42:08:04
 */
@Service
public class CheckworkServiceImpl implements ICheckworkService {
    @Autowired
    private CheckworkDao checkworkDao;

    @Override
    public List<Checkwork> findAll() {
        return checkworkDao.findAll();
    }

    @Override
    public Checkwork findById(String id) {
        return checkworkDao.findById(id);
    }

    @Override
    public void deleteById(String id) {
        checkworkDao.deleteById(id);
    }

    @Override
    public void updateById(Checkwork checkwork) {
        checkworkDao.updateById(checkwork);
    }

    @Override
    public void save(Checkwork checkwork) {
        checkworkDao.save(checkwork);
    }

    @Override
    public void addOrUpdate(Checkwork checkwork, HttpServletRequest httpServletRequest) {
        //保存
        if (StrUtil.isEmpty(checkwork.getId())|| findById(checkwork.getId()) == null){
            checkwork.setId(StrUtil.uuid());
            checkwork.setCreateBy(JobUtil.getUserId(httpServletRequest));
            checkwork.setCreateTime(new Date());
            save(checkwork);
            return;
        }
        //修改
        updateById(checkwork);
    }
}